package com.algorithm.merger;/*
 *@Author:DOWN
 *@Date:2022/1/5 17:22
 *@Comment:
 */

import com.algorithm.testutils.ArrayGenerator;
import com.algorithm.testutils.SortingHelp;

public class Solution {
    public static ListNode removeElements(ListNode head, int val) {
        if (head == null) {
            return null;
        }
        ListNode res = removeElements(head.next, val);
        //如果自身相等 返回下节点 or 挂载下节点
        if (head.val == val) {
            return res;
        } else {
            head.next = res;
            return head;
        }
    }

    public static void main(String[] arrs) {
        ListNode node = new ListNode(1);
        node.next = new ListNode(4);
        node.next.next = new ListNode(3);
        node.next.next.next = new ListNode(4);
        ListNode view = removeElements(node, 4);
        while (view != null) {
            System.out.println(view.val + "");
            view = view.next;
        }
    }
}

class ListNode {
    int val;
    ListNode next;

    ListNode() {
    }

    ListNode(int val) {
        this.val = val;
    }

    ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }

}
